package db

import androidx.room.TypeConverter
import com.example.campuslink.commen.db.comment.CommentTable
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class ListStringConverter {
    private val gson = Gson()
    private val listType = object : TypeToken<MutableList<String>>() {}.type

    @TypeConverter
    fun fromString(value: String): MutableList<String>? {
        return if (value.isBlank()) null else gson.fromJson(value, listType)
    }

    @TypeConverter
    fun fromList(list: MutableList<String>?): String {
        return gson.toJson(list ?: emptyList<String>())
    }
//    private val gson = Gson()
//
//    @TypeConverter
//    fun fromString(value: String?): List<String> {
//        if (value == null) {
//            return ArrayList()
//        }
//        val listType = object : TypeToken<List<String?>?>() {}.type
//        return gson.fromJson(value, listType)
//    }
//
//    @TypeConverter
//    fun fromList(list: List<String?>?): String {
//        return gson.toJson(list)
//    }
}